package com.lzw.d25bingso;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class WelcomeActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private List<View> data;
    private int views []={R.layout.welcome_1,R.layout.welcome_2,R.layout.welcome_3};
    private WelAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        viewPager = (ViewPager) findViewById(R.id.view_pager_id);
        data = new ArrayList<>();
        for (int i = 0; i<views.length; i++){
            LinearLayout layout = (LinearLayout) LayoutInflater.from(this).inflate(views[i],null,false);
            data.add(layout);

        }

        adapter = new WelAdapter();
        viewPager.setAdapter(adapter);

//        LinearLayout layout= (LinearLayout) data.get(2);
//        Button button = (Button) layout.getChildAt(0);



    }
    public void show(View v){
        Intent intent = new Intent(this,InfoActivity.class);
        startActivity(intent);
        finish();
    }
    public class WelAdapter extends PagerAdapter{

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(data.get(position));
            return data.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(data.get(position));
        }


        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    }


}
